//
//  meViewController.m
//  FastRunDemo
//
//  Created by 苟亚明 on 16/9/16.
//  Copyright © 2016年 苟亚明. All rights reserved.
//

#import "meViewController.h"
#import "XCPullMenu.h"
#import "meHeaderView.h"
#import "meCell.h"
#import "meModel.h"
#import "personSettingViewController.h"
#import "myIntegralViewController.h"
#import "KPNaviViewController.h"
#import "walletViewController.h"
#import "makeMoneyTableViewController.h"
#import "XCFeedBackViewController.h"
#import "systemMessageViewController.h"
#import "LoginViewController.h"
#import "sureIdViewController.h"
#import "personInforViewController.h"
#import "rankListViewController.h"
#import "signViewController.h"
@interface meViewController () <UITableViewDelegate,UITableViewDataSource>
/** 下拉菜单*/
@property (nonatomic, strong) XCPullMenu *menu;
/** tableView*/
@property (nonatomic, strong) UITableView *tableView;
/** 图片数组*/
@property (nonatomic, strong) NSArray *arrayPic;
/** 选项数组*/
@property (nonatomic, strong) NSArray *arrayOption;
/** footer*/
@property (nonatomic, strong) UIView *footerView;
@end

@implementation meViewController

#pragma make - viewlife

//- (void)viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:animated];
//    self.navigationController.navigationBar.hidden = NO;
//}
//- (void)viewWillDisappear:(BOOL)animated{
//    [super viewWillDisappear:animated];
//    self.navigationController.navigationBar.hidden = NO;
//}
//- (void)viewDidDisappear:(BOOL)animated{
//    [super viewDidDisappear:animated];
//    self.navigationController.navigationBar.hidden = NO;
//}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    UIImage *image = [UIImage imageNamed:@"transparent-1"];
    [self.navigationController.navigationBar setBackgroundImage:image
                                                  forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:image];
    
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置数据
    [self setupData];
    // 设置导航栏
    [self setupNavi];
    // 设置tableView
    [self setupTableView];
    
    
}


/**
 * 设置数据
 */
- (void)setupData{
    self.arrayPic = @[@"me_cell_heart",
                      @"me_cell_wallet",
                      @"me_cell_authentication",
                      @"me_btn_makeMoney",
                      @"me_btn_ranking"];
    self.arrayOption = @[@"关注微博微信",
                         @"我的钱包",
                         @"我的认证",
                         @"我要赚钱",
                         @"排行榜"];
}



/**
 * 设置导航栏
 */
- (void)setupNavi{
    
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"me_btn_setting" highImage:@"me_btn_setting" target:self action:@selector(BtnSettingClick)];
}

static NSString *const meCellID = @"meCellID";
/**
 * 设置tableView
 */
- (void)setupTableView{
    
    // 初始化tableView
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, GYMScreenW, GYMScreenH - 49)];
    
    // 设置头部
    meHeaderView *header = [[[NSBundle mainBundle]loadNibNamed:@"meHeaderView" owner:nil options:nil]lastObject];
    // 给header添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headerClick:)];
    [header addGestureRecognizer:tap];
    // 头部事件触发
    [header.btnIntegral addTarget:self action:@selector(btnIntegralClick) forControlEvents:UIControlEventTouchUpInside];
    [header.btnSign addTarget:self action:@selector(btnSignClick) forControlEvents:UIControlEventTouchUpInside];
    [header.btnSetting addTarget:self action:@selector(BtnSettingClick) forControlEvents:UIControlEventTouchUpInside];
    header.frame = CGRectMake(0, 0, GYMScreenW, 244);
    self.tableView.tableHeaderView = header;
    
    // 注册cell
    [self.tableView registerNib:[UINib nibWithNibName:@"meCell" bundle:nil] forCellReuseIdentifier:meCellID];
    
    // 设置代理
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    // 设置尾部
    self.footerView = [[UIView alloc]init];
    self.footerView.frame = CGRectMake(0, 0, GYMScreenW, 80);
    
    UIButton *btn = [[UIButton alloc]init];
    [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [btn setTitle:@"退出登录" forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"me_btn_out"] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [btn sizeToFit];
    
    btn.centerX = self.footerView.centerX;
    btn.centerY = self.footerView.height / 2;
    [btn addTarget:self action:@selector(footerViewClick) forControlEvents:UIControlEventTouchUpInside];
    [self.footerView addSubview:btn];
    
    self.tableView.tableFooterView = self.footerView;
    
    [self.view addSubview:self.tableView];
    
}

#pragma mark - action
- (void)BtnSettingClick{
    personSettingViewController *vc = [[personSettingViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
// 退出登录
- (void)footerViewClick{
    
    LoginViewController *vc = [[LoginViewController alloc]init];
    KPNaviViewController *navi = [[KPNaviViewController alloc]initWithRootViewController:vc];
    self.view.window.rootViewController = navi;
}

// 我的积分
- (void)btnIntegralClick{
    myIntegralViewController *vc = [[myIntegralViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)btnSignClick{
    signViewController *vc = [[signViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}



- (void)headerClick:(UITapGestureRecognizer *)tap{
    personInforViewController *vc = [[personInforViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - <UITbleViewDelegate>
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arrayPic.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    meCell *cell = [tableView dequeueReusableCellWithIdentifier:meCellID];
    cell.imgIcon.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",self.arrayPic[indexPath.row]]];
    cell.lblOption.text = self.arrayOption[indexPath.row];
    return cell;
}

#pragma mark - <XCPullMenuDelegate>
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.row == 1){ // 我的钱包
        
        walletViewController *vc = [[walletViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if(indexPath.row == 2){ // 我要认证
        
        sureIdViewController *vc = [[sureIdViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 4){ // 排行榜
        rankListViewController *vc = [[rankListViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
        
    } else if (indexPath.row == 3){// 我要赚钱
        
        makeMoneyTableViewController *vc = [[makeMoneyTableViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
        
    }
    
}


@end
